# Create your views here.
import datetime
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template import loader, Context
from django.utils.safestring import mark_safe

from pypsqueak.profile.models import *

def profile_css(request, type, pk ):
	""" Retrieve css file for the given profile type and id value """

	if type == "UserProfile":
		profile = get_object_or_404(UserProfile, pk=pk)
	elif type == "GroupProfile":
		profile = get_object_or_404(GroupProfile, pk=pk)
	else:
		raise 'Unknown type css ' + type

	response = HttpResponse(mimetype='text/css')

	t = loader.get_template('profile.css')
	c = Context( {
		#'username': user.username,
		'background_color':'rgb(00,00,00)',
		'background_font_color': 'rgb(255,255,255)',
		'user_background_color': profile.background_canvas_color,
		'user_background_font_color': 'white',
		'user_foreground_color': profile.foreground_canvas_color,
		'user_foreground_font_color': profile.foreground_font_color
		})

	response.write(t.render(c))

	return response

def base_css(request ):
	""" CSS headers for the general site (no profile) """

	response = HttpResponse(mimetype='text/css')

	t = loader.get_template('profile.css')
	c = Context( {
		'background_color':'rgb(00,00,00)',
		'background_font_color': 'rgb(255,255,255)',
		'user_background_color': '#596380',
		'user_foreground_color': '#CFD4E6',
		'user_foreground_font_color': 'black'
		})

	response.write(t.render(c))

	return response